package com.foreveross.taskservice.web.controller.task;

import javax.annotation.Resource;

import org.dayatang.domain.InstanceFactory;
import org.dayatang.querychannel.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.foreveross.taskservice.application.task.statsdetail.ITaskDetailApplication;
import com.foreveross.taskservice.application.task.statsdetail.vo.BaseTaskVO;
import com.foreveross.taskservice.infra.db.HBaseCellModel;
import com.foreveross.taskservice.infra.db.HBaseRowModel;
import com.foreveross.taskservice.web.controller.auth.BaseController;

@Controller
@RequestMapping("/task/TaskDetail")
public class TaskDetailController extends BaseController{
	@Resource(name="taskDetailApplicationImpl")
	private ITaskDetailApplication taskDetailApplication;
	
	@ResponseBody
//	@RequestMapping(params="method=detailByChannelIdAndTaskStatus")
	@RequestMapping("/detail")
	public Page detail(BaseTaskVO vo )throws Exception{
		@SuppressWarnings("rawtypes")
		Page page=taskDetailApplication.query(vo.getChannelCode(),vo.getTaskStatus(),vo.getGrabDateStr(), vo.getPageLen(), vo.getPageIndex());
//		return "task/TaskDetail_detailStatusList";
		
		return page;
	}
	
	
	@RequestMapping(value = "/sourceFile", produces = "text/html;charset=UTF-8")  
	public  String sourceFile(ModelMap modelMap, @RequestParam String id)throws Exception{
		HBaseRowModel rowModel = InstanceFactory.getInstance(com.foreveross.taskservice.infra.db.HbaseManager.class)
				.getOneRecord("CRAWL_PF_SOURCE_DATA", id);
		HBaseCellModel model = rowModel.lookupCell("CONTENTS", "CONTENTS");
		modelMap.put("result", model.getValue());
		return "task/TaskDetail_crawlTaskSource";
	}
	
	/*@RequestMapping(value = "/taskSource", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")  
	public @ResponseBody String successRate(@RequestParam String id)throws Exception{
		String result="";
		if(id !=null && !id.isEmpty()){
			String tableName="CRAWL_PF_SOURCE_DATA";
			//查询hbase
			ResultScanner re=HBaseHelper.getRecords(tableName, id,id,new String[]{"CONTENTS"});
			if(re !=null){
				for (Result r : re) {
					for (KeyValue kv : r.raw()) {
						String c= new String(kv.getQualifier());
						if(c.equals("CONTENTS")){
							result+=new String(kv.getValue(),"UTF-8");
							continue;
						}
					}
				}
			}
		}
		return result;
	}*/
}


